<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
</head>
<body>
<div id="app">
    <el-container>
        <el-header style="background-color: #0095d7">
            <h1 style="color: white;font-size: 22px">
                新点俱乐部管理系统
                <span style="float:right;font-size: 15px">欢迎回来!<a href="javascript:void(0)"@click="logout()">退出登录</a></span>
            </h1>
        </el-header>
        <el-container>
            <el-aside width="200px" style="overflow: hidden">
                <!--导航菜单开始-->
                <el-menu @select="handleSelect">
                    <!--添加子菜单-->
                    <el-submenu index="1">
                        <!--添加子菜单标题-->
                        <template slot="title">
                            <i class="el-icon-s-flag"></i>
                            <span>俱乐部管理</span>
                        </template>
                        <!--添加菜单项-->
                        <el-menu-item index="1-1">俱乐部列表</el-menu-item>
                        <el-menu-item index="1-2" @click="insertClub()">添加俱乐部</el-menu-item>
                    </el-submenu>
                </el-menu>
                <!--导航菜单结束-->
            </el-aside>
            <el-main>
                <!--分类表格开始-->
                <el-table v-if="currentIndex=='1-1'" :data="clubArr" style="width: 100%" border="true">
                    <el-table-column v-model="clubArr.id" prop="id" label="编号" width="150">
                    </el-table-column>
                    <el-table-column v-model="clubArr.name" prop="name" label="俱乐部名称" width="150">
                    </el-table-column>
                    <el-table-column v-model="clubArr.type" prop="type" label="俱乐部类型" width="150">
                    </el-table-column>
<!--                    <el-table-column v-model="club.time" prop="time" label="创建时间" width="150">-->
<!--                    </el-table-column>-->
                    <el-table-column v-model="clubArr.count" prop="count" label="活动次数" width="150">
                    </el-table-column>
                    <el-table-column v-model="clubArr.vip" prop="vip" label="会员数量" width="150">
                    </el-table-column>

                    <el-table-column label="操作">
                        <template slot-scope="scope">
                            <el-button size="mini" @click="updateClub(scope.row)"
                                       type="success">修改
                            </el-button>
                            <el-popconfirm title="您确认删除此分类吗?"
                                           @confirm="clubDelete(scope.$index, scope.row)">
                                <el-button
                                        slot="reference"
                                        size="mini"
                                        type="danger">删除
                                </el-button>
                            </el-popconfirm>
                        </template>
                    </el-table-column>
                </el-table>
                <!--分类表格结束-->
            </el-main>
        </el-container>
    </el-container>
</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                currentIndex: "1-1",
                clubArr: [],
                club:{id:"",name:"",person:"",type:"",time:"",count:"",vip:""}
            }
        },
        methods: {
            updateClub(club) {
                //跳转到修改商品页面 把id传递过去
                location.href = "/updateClub.html?id=" + club.id;
            },
            clubDelete(i, club) {
                axios.get("/club/delete?id=" + club.id).then(function (response) {
                    //删除数组中的数据
                    v.clubArr.splice(i, 1);
                })
            },
            handleSelect(){
            },
            insertClub(){
                location.href = "/insertClub.html"
            }
        },
        created: function () {
            axios.get("/club/select").then(function (response) {
                console.log(response.data)
                v.clubArr = response.data;
            })
        }
    })
</script>
</html>